#include "stdafx.h"
#include "sprite.h"

Sprite::Sprite() :
    _width(0),
    _height(0),
    _texture(0),
    _depth(0.0f)
{
}

Sprite::Sprite(float width, float height, GLuint texture, float depth) :
    _width(width),
    _height(height),
    _texture(texture),
    _depth(depth)
{
}

Sprite::~Sprite()
{
}

void Sprite::render(float x, float y) const
{
    glEnable(GL_TEXTURE_2D);
    glColor4f(1, 1, 1, 1);
    glBindTexture(GL_TEXTURE_2D, _texture);
    glBegin(GL_QUADS);
    {
        glTexCoord2i(0, 0);
        glVertex3f(x - 0.5f * width(), y - 0.5f * height(), _depth);
        glTexCoord2i(0, 1);
        glVertex3f(x - 0.5f * width(), y + 0.5f * height(), _depth);
        glTexCoord2i(1, 1);
        glVertex3f(x + 0.5f * width(), y + 0.5f * height(), _depth);
        glTexCoord2i(1, 0);
        glVertex3f(x + 0.5f * width(), y - 0.5f * height(), _depth);
    }
    glEnd();
    glDisable(GL_TEXTURE_2D);
}

float Sprite::width() const
{
    return _width;
}

float Sprite::height() const
{
    return _height;
}
